package com.huiztech.kaoqinji;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Toast;

import com.baidu.mapapi.map.MapView;
import com.baidu.platform.comapi.basestruct.GeoPoint;

class MapViewTest extends MapView {
    Context context;
    public MapViewTest(Context context) {
        super(context);
        this.context=context;
    }

    public MapViewTest(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MapViewTest(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //获得屏幕点击的位置
        int x = (int) event.getX();
        int y = (int) event.getY();
        //将像素坐标转为地址坐标
        GeoPoint pt = this.getProjection().fromPixels(x, y);
        Toast.makeText(context, pt.getLatitudeE6()+"=="+pt.getLongitudeE6(), Toast.LENGTH_SHORT).show();
        return super.onTouchEvent(event);
    }
}